<?php

/**
 * This is the model class for table "phancong".
 *
 * The followings are the available columns in table 'phancong':
 * @property string $maNhom
 * @property integer $magvchinh
 * @property integer $magvphu
 * @property integer $ghichu
 */
class Phancong extends CActiveRecord
{
	public $nhomlop_makhoilop_search;
	public $nhomlop_namhoc_search;
	public $nhomlop_hocki_search;
	public $monhoc_mamh_search;
	public $chuongtrinh_khoaphutrach_search;
	public $chuongtrinh_khoaday_search;
	
	public function tableName()
	{
		return 'phancong';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('maNhom', 'required'),
			array('magvchinh, magvphu, ghichu', 'numerical', 'integerOnly'=>true),
			array('maNhom', 'length', 'max'=>128),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('maNhom, magvchinh, magvphu, ghichu, nhomlop.makhoilop, nhomlop.namhoc, nhomlop.hocki, nhomlop_namhoc_search,nhomlop_makhoilop_search, nhomlop_hocki_search, monhoc.mamh, monhoc_mamh_search, chuongtrinh.madonvi, chuongtrinh_khoaphutrach_search, chuongtrinh.madonviday, chuongtrinh_khoaday_search', 'safe', 'on'=>'search'),
		);
	}
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'nhomlop'=>array( self::BELONGS_TO, 'Nhomlop', 'maNhom' ),
			'monhoc' => array(self::BELONGS_TO, 'Monhoc', array('mamh'=>'mamh'), 'through'=>'nhomlop'),
			'chuongtrinh' => array(self::BELONGS_TO, 'Chuongtrinh', array('mamh'=>'mamh'), 'through'=>'monhoc'),
		);
	}
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'maNhom' => 'Ma Nhom',
			'magvchinh' => 'Magvchinh',
			'magvphu' => 'Magvphu',
			'ghichu' => 'Ghichu',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		$criteria->with=array('nhomlop');
		$criteria->with=array('monhoc');
		$criteria->with=array('chuongtrinh');
		$criteria->compare('maNhom',$this->maNhom,true);
		$criteria->compare('magvchinh',$this->magvchinh);
		$criteria->compare('magvphu',$this->magvphu);
		$criteria->compare('ghichu',$this->ghichu);
		
		$criteria->compare('nhomlop.makhoilop',$this->nhomlop_makhoilop_search);
		$criteria->compare('nhomlop.namhoc',$this->nhomlop_namhoc_search);
		$criteria->compare('nhomlop.hocki',$this->nhomlop_hocki_search);
		
		$criteria->compare('monhoc.mamh',$this->monhoc_mamh_search,true);
        
		$criteria->compare('chuongtrinh.madonvi',$this->chuongtrinh_khoaphutrach_search);
		$criteria->compare('chuongtrinh.madonviday',$this->chuongtrinh_khoaday_search,true);
 		
		return new CActiveDataProvider($this, array(
	 		'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Phancong the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
